Overall Quotes Analysis

total_by_year <- quotes %>% 
  group_by(talk_year) %>% 
  summarise("total_quotes" = n())

ggplot(data = total_by_year) + 
  geom_area(mapping = aes(x = talk_year, y = total_quotes), fill="steelblue", alpha=0.5) +
  labs(title="Total Quotes by Year",
       x = "Year", 
       y = "Total Scriptures Quoted") +
  theme_bw()

book_by_year <- quotes %>% 
  group_by(quad_book, talk_year) %>% 
  summarise("total_quotes" = n())

big_book_by_year <- quotes %>% 
  group_by(overall_book, talk_year) %>% 
  summarise("total_quotes" = n())

ggplot(data = book_by_year) + 
  geom_area(mapping = aes(x = talk_year, y = total_quotes, fill = quad_book), position="identity", alpha = 0.5) +
  labs(title="Total Quotes by Book and Year",
       x = "Year", 
       y = "Total Scriptures Quoted per Book") +
  theme_bw()

ggplot(data = book_by_year) + 
  geom_line(mapping = aes(x = talk_year, y = total_quotes, color = quad_book), size=1) +
  labs(title="Total Quotes by Book and Year",
       x = "Year", 
       y = "Total Scriptures Quoted per Book") +
  theme_bw()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

ggplot(data = big_book_by_year) + 
  geom_line(mapping = aes(x = talk_year, y = total_quotes, color = overall_book), size=1) +
  labs(title="Total Quotes by Book and Year",
       x = "Year", 
       y = "Total Scriptures Quoted per Book") +
  theme_bw()

ggplot(data = filter(big_book_by_year, overall_book == "Book of Mormon")) + 
  geom_line(mapping = aes(x = talk_year, y = total_quotes, color = overall_book), size=1) +
  geom_smooth(mapping = aes(x = talk_year, y = total_quotes))

  labs(title="Total Quotes by Book and Year",
       x = "Year", 
       y = "Total Scriptures Quoted per Book") +
  theme_bw()
## NULL

What are the top 10 Scriptures of all time?

all_time <- quotes %>% 
  filter(scripture != "null null:null") %>% # Removes the null values from the data.
  group_by(scripture) %>% 
  summarise("count" = n()) %>% 
  arrange(desc(count)) %>% 
  mutate("rank" = rank(desc(count), ties.method = "max")) %>% 
  filter(rank %in% c(1:10))

all_time_10 <- quotes %>% 
  filter(scripture != "null null:null") %>% # Removes the null values from the data.
  group_by(scripture) %>% 
  summarise("count" = n()) %>% 
  arrange(desc(count)) %>% 
  mutate("rank" = rank(desc(count), ties.method = "max")) %>% 
  filter(rank %in% c(1:10)) %>% 
  left_join(y = verses, x = all_time, by = "scripture") %>% 
  select(c("scripture", "count", "rank", "text"))

history_all_time_10 <- quotes %>% 
  filter(scripture %in% all_time_10$scripture) %>% 
  mutate("decade" = paste(str_sub(talk_year, 1, 3), 0, sep="")) %>% 
  group_by(decade)

pander(select(all_time_10, c("scripture", "count", "rank")))
scripture count rank
Moses 1:39 166 1
Matthew 11:28 114 2
Mosiah 18:9 113 3
Joseph Smith History 1:17 110 4
2 Nephi 31:20 104 5
Matthew 25:40 89 6
Matthew 22:39 85 7
Mosiah 3:19 84 8
Matthew 22:37 82 9
John 14:27 81 10
ggplot(data = history_all_time_10) + 
  geom_bar(mapping = aes(x = decade, fill = scripture), size=1, position="dodge") +
  labs(title="Total Quotes Top 10 Scriptures all Time",
       x = "Year", 
       y = "Total Scriptures Quoted per Book") +
  theme_bw()

line_all_time_history <- history_all_time_10 %>% 
  group_by(decade = as.numeric(decade), scripture) %>% 
  summarise("count" = n())


ggplot(data = line_all_time_history) + 
  geom_line(mapping = aes(x = decade, y = count, color = scripture), size=1) +
  labs(title="Total Quotes Top 10 Scriptures all Time",
       x = "Year", 
       y = "Total Scriptures Quoted per Book") +
  theme_bw()

Displaying them over time?

What about in different decades?

Creating a Grid:

# Creating the Full Verses Image:
my_plot <- ggplot(data = verses, aes(x = verse, y = fct_rev(factor(book_chapter, levels = verse_order)), fill = quoted)) +
  geom_tile(col = "white") +
  coord_equal(ratio=2.33) +
  scale_fill_manual(values = c("NA" = "white", "Found" = "red")) +
  scale_x_continuous(breaks = unique(verses$verse)) + 
  theme_minimal() +
  theme(
    legend.position = "right",
    panel.background = element_rect(fill = "white"),
    axis.text.y = element_text(size = rel(0.5)),
    axis.text.x = element_blank(),
    axis.title.y = element_blank()
  ) + 
  guides(fill = "none")

ggsave(filename = "C:/Users/theka/Pictures/my_plot.png", plot = my_plot, width = 8, height = 120, units = "in", limitsize = FALSE, bg = "white")
# Creating the Book Chapter Image:
my_plot2 <- ggplot(data = chapters, aes(x = chapter, y = fct_rev(factor(book, levels = book_ordering)), fill = quoted)) +
  geom_tile(col = "white") +
  coord_equal(ratio=2.33) +
  scale_fill_manual(values = c("NA" = "white", "Found" = "red")) +
  scale_x_continuous(breaks = unique(chapters$chapter)) + 
  theme_minimal() +
  labs(x = "Chapter") +
  theme(
    legend.position = "right",
    panel.background = element_rect(fill = "white"),
    axis.text.y = element_text(size = rel(0.65)),
    axis.text.x = element_blank(),
    axis.title.y = element_blank()
  ) + 
  guides(fill = "none")

ggsave(filename = "C:/Users/theka/Pictures/my_plot2.png", plot = my_plot2, width = 8, height = 9, units = "in", limitsize = FALSE, bg = "white")
levels_check <- verses %>%
  select(book_chapter) %>% 
  mutate("check" = case_when(
    book_chapter %in% verse_order ~ "FOUND",
    TRUE ~ "NOT"
  ))
library(DT)

datatable(
  select(filter(quotes, talk_year >= 2000), c("talk_year", "talk_month", "talk_day", "talk_session", "scripture", "speaker")),
  colnames = c("Combined Scripture", "Year", "Month", "Day", "Session ID", "Speaker"),
  options = list(
    searching = TRUE,
    searchCols = list(
      list(targets = 5, search = "applied")
    )
  )
)
## Warning in instance$preRenderHook(instance): It seems your data is too big for
## client-side DataTables. You may consider server-side processing:
## https://rstudio.github.io/DT/server.html
# Remove zero values in quote_count
plot_3d <- verses %>% 
  mutate(quote_count = ifelse(quote_count == 0, NA, quote_count))

# Convert columns to numeric if they are not already
plot_3d$verse <- as.numeric(plot_3d$verse)
plot_3d$quote_count <- as.numeric(plot_3d$quote_count)

fig <- plot_ly(data = plot_3d, x = ~verse, y = ~factor(book_chapter, levels = verse_order), z = ~quote_count) %>% 
  add_markers(size = 5) %>% 
  layout(
    scene = list(
      xaxis = list(title = 'Verse'),
      yaxis = list(title = 'Chapter'),
      zaxis = list(title = 'Quotes'),
      aspectratio = list(x = 1, y = 3, z = 1)
    ),
    xaxis = list(title = 'Overall Book')  # Add x-axis title
  )

fig
## Warning: Ignoring 33510 observations
# Plotting the Book Chapter Image in 3D:

chapter_fig <- plot_ly(data = chapters, x = ~chapter, y = ~factor(chapters$book, levels = book_ordering), z = ~quote_count) %>% 
  add_markers(size = 5) %>% 
  layout(
    scene = list(
      xaxis = list(title = 'Chapter'),
      yaxis = list(title = 'Book'),
      zaxis = list(title = 'Quotes'),
      aspectratio = list(x = 1, y = 3, z = 1)
    ),
    xaxis = list(title = 'Overall Book')  # Add x-axis title
  )

chapter_fig
## Warning: Ignoring 565 observations
testing <- verses %>% 
  group_by(book_chapter) %>% 
  summarise(verse_count = n())